package com.yanq.liancar.activity;
/*
 *  @创建者     Administrator
 *  @创建时间   2018/11/9  16:50
 *  @描述       ${TODO}
 */


import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.google.gson.Gson;
import com.gyf.barlibrary.ImmersionBar;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.vondear.rxtool.view.RxToast;
import com.vondear.rxui.view.dialog.RxDialogSure;
import com.yanq.liancar.R;
import com.yanq.liancar.activity.base.BaseToolbarActivity;
import com.yanq.liancar.bean.BaseBean;
import com.yanq.liancar.bean.QueryByoNumBean;
import com.yanq.liancar.url.Config;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class VerificationResultActivity extends BaseToolbarActivity {
    @BindView(R.id.tv_shopName)
    TextView tvShopName;
    @BindView(R.id.tv_serviceName)
    TextView tvServiceName;
    @BindView(R.id.btn_sure)
    Button btnSure;
    @BindView(R.id.btn_cancel)
    Button btnCancel;
    private String orderId;
    private int type;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_verificationresult);
        ImmersionBar.with(this).statusBarDarkFont(true).statusBarColor(R.color.white).init();
        ButterKnife.bind(this);
        mTvTitle.setText("验证结果");
        orderId=getIntent().getStringExtra("code");
        tvShopName.setText(getIntent().getStringExtra("shopName"));
        tvServiceName.setText(getIntent().getStringExtra("serviceName"));
        type=getIntent().getIntExtra("type",0);
    }

    @OnClick({R.id.btn_sure, R.id.btn_cancel})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_sure:
                if (type==1){
                    initOkGo();
                }else if (type==2){
                    serviceVoucher ();
                }
                break;
            case R.id.btn_cancel:
                finish();
                break;
        }
    }

    //确认验券(订单券)
    private void initOkGo() {
        OkGo.<String>post(Config.s + "llc/carServiceOrderController/updatestate")
                .tag(this)
                .params("oNum", orderId)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        Gson gson = new Gson();
                        BaseBean byoNumBean = gson.fromJson(response.body(), BaseBean.class);
                        if (byoNumBean.isIsSuccess()) {
                          RxToast.success("验证成功");
                          finish();
                        } else {
                            RxToast.error(byoNumBean.getOutputMessage());
                        }

                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        RxToast.error("服务器连接错误");
                    }
                });
    }


    //确认验券(服务券)
    private void serviceVoucher () {
        OkGo.<String>post(Config.s + "llc/api/serviceVoucherController/updateConsumeVoucherOrderStatus")
                .tag(this)
                .params("oNum", orderId)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        Gson gson = new Gson();
                        BaseBean byoNumBean = gson.fromJson(response.body(), BaseBean.class);
                        if (byoNumBean.isIsSuccess()) {
                            RxToast.success("验证成功");
                            finish();
                        } else {
                            RxToast.error(byoNumBean.getOutputMessage());
                        }

                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        RxToast.error("服务器连接错误");
                    }
                });
    }


}
